package com.wingsboat.common.filterChain.pipline;

import com.wingsboat.common.filterChain.chain.DefaultWbFilterChain;
import com.wingsboat.common.filterChain.chain.WbFilterChain;
import com.wingsboat.common.filterChain.context.WbFilterContext;
import com.wingsboat.common.filterChain.filter.WbFilter;

/**
 * @Author: wangzhong
 * @Date: 2023/11/16 20:45
 * @Description:
 **/

public abstract class AbstractWbPipeline<T extends WbFilterContext> implements WbPipeline<T> {
    private DefaultWbFilterChain last;
    @Override
    public WbFilterChain getFilterChain() {
        return last;
    }

    @Override
    public WbPipeline<T> addFilter(WbFilter<T> filter) {
        DefaultWbFilterChain node = new DefaultWbFilterChain(filter,last);
        last = node;
        return this;
    }

    @Override
    public void handler(T context) {
        last.handler(context);
    }
}
